<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-equipInfo-add">
			<input name="deptId"  type="hidden" id="treeId"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">名称型号：</label>
				<div class="col-sm-8">
					<input id="namePn" name="namePn" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">序列号：</label>
				<div class="col-sm-8">
					<input id="serialNo" name="serialNo" class="form-control" type="text">
				</div>
			</div>
			<!-- TODO 可以参考新建菜单中 图标选择 -->
			<div class="form-group">	
				<label class="col-sm-3 control-label">负责人：</label>
				<div class="col-sm-8">
					<input id="supervisorId" name="supervisorId" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">购置日期：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control click-time" id="clickTime" placeholder="购置日期" name="buyTime"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">总价格：</label>
				<div class="col-sm-8">
					<input id="totalPrice" name="totalPrice" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">高值设备：</label>
				<div class="col-sm-8">
					<select id="valueFlag" class="form-control m-b" th:with="type=${@dict.getType('equip_info_value')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">质保期(月)：</label>
				<div class="col-sm-8">
					<input id="warranty" name="warranty" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">放置地点：</label>
				<div class="col-sm-8">
					<input id="place" name="place" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">生产厂家：</label>
				<div class="col-sm-8">
					<input id="manufacturer" name="manufacturer" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">生产国家：</label>
				<div class="col-sm-8">
					<input id="country" name="country" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">售后电话：</label>
				<div class="col-sm-8">
					<input id="supportPhone" name="supportPhone" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">功能特色：</label>
				<div class="col-sm-8">
					<textarea id="features" name="features" class="form-control"></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">规格及技术指标：</label>
				<div class="col-sm-8">
					<textarea id="specification" name="specification" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
		$("#form-equipInfo-add").validate({
			rules:{
                deptId:{
					required:true
				},
                namePn:{
                    required:true
                },
                serialNo:{
                    required:true
                },
                supervisorId:{
                    required:true,
                    digits:true
                },
                buyTime:{
                    required:true,
                    date:true
                },
                valueFlag:{
                    required:true
                },
                warranty:{
                    required:true,
                    digits:true,
                    range: [1,9999]
                }
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                add();
	        }
	    }

        function add() {
            var deptId = $("input[name='deptId']").val();
            var namePn = $("input[name='namePn']").val();
            var serialNo = $("input[name='serialNo']").val();
            var supervisorId = $("input[name='supervisorId']").val();
            var buyTime = $("input[name='buyTime']").val()+" 00:00:00";
            var totalPrice = $("input[name='totalPrice']").val();
            var valueFlag = $("#valueFlag option:selected").val();
            var warranty = $("input[name='warranty']").val();
            var place = $("input[name='place']").val();
            var manufacturer = $("input[name='manufacturer']").val();
            var country = $("input[name='country']").val();
            var supportPhone = $("input[name='supportPhone']").val();
            var features = $("input[name='features']").val();
            var specification = $("input[name='specification']").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "equipment/account/add",
                data : {
                    "deptId": deptId,
                    "namePn": namePn,
                    "serialNo": serialNo,
                    "supervisorId": supervisorId,
                    "buyTime": buyTime,
                    "totalPrice": totalPrice,
                    "valueFlag": valueFlag,
                    "warranty": warranty,
                    "place": place,
                    "manufacturer": manufacturer,
					"country":country,
					"supportPhone":supportPhone,
					"features":features,
					"specification":specification
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
	</script>
</body>
</html>
